<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('项目落地情况') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('年份')" prop="nianfen">
        <el-date-picker
          v-model="queryParams.nianfen"
          type="year"
          clearable
          size="small"
          value-format="yyyy"
          placeholder="选择年"
        />
      </el-form-item>
      <el-form-item :label="$t('季度')" prop="jidu">
        <el-select v-model="queryParams.jidu" :placeholder="$t('季度')" clearable>
          <el-option
            v-for="dict in jiduOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:implementation:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="companyImplementationList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('年份')" align="center" prop="nianfen" min-width="150" />
      <el-table-column :label="$t('季度')" align="center" prop="jidu" min-width="150" :formatter="jiduFormat" />
      <el-table-column :label="$t('面积(m²)')" align="center" prop="area" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.area) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('位置')" align="center" prop="location" min-width="200" show-overflow-tooltip />
      <el-table-column :label="$t('目前员工人数')" align="center" prop="upStaffNumber" min-width="150" />
      <el-table-column :label="$t('中级及以上专业技术人员(数量)')" align="center" min-width="250" prop="intermediateNumber" />
      <el-table-column :label="$t('国家职业资格三级及以上技能人员(数量)')" align="center" min-width="260" prop="gjzyzgsjiNumber" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" min-width="200" fixed="right">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['deal:implementation:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['deal:implementation:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目落地情况对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <companyImplementationForm ref="companyImplementationForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listCompanyImplementation, delCompanyImplementation, exportCompanyImplementation } from '@/api/sass/lanwan/companyImplementation'
import companyImplementationForm from './companyImplementationForm.vue'
export default {
    components: {
        companyImplementationForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 项目落地情况表格数据
          companyImplementationList: [],
          // 弹出层标题
          title: '项目落地情况',
          // 是否显示弹出层
          formOpen: false,
        // 季度字典
        jiduOptions: [],

          // 查询参数
          queryParams: {
              companyId: this.$route.query.companyId,
              nianfen: undefined,
              jidu: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('report_type').then(response => {
          this.jiduOptions = response.data
      })
  },
  methods: {
    /** 查询项目落地情况列表 */
    getList() {
        this.loading = true
        listCompanyImplementation(this.queryParams).then(response => {
            this.companyImplementationList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },
    // 季度字典翻译
    jiduFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.jiduOptions, row.jidu)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            dealId: undefined,
            companyId: undefined,
            reportName: undefined,
            nianfen: undefined,
            jidu: undefined,
            area: undefined,
            location: undefined,
            upStaffNumber: undefined,
            intermediateNumber: undefined,
            gjzyzgsjiNumber: undefined,
            alreadyPatentNumber: undefined,
            alreadyInventionPatentsNumber: undefined,
            alreadyUtilityPatentsNumber: undefined,
            alreadyExteriorNumber: undefined,
            alreadySoftNumber: undefined,
            applyingPatentNumber: undefined,
            applyingInventionPatentsNumber: undefined,
            applyingExteriorNumber: undefined,
            applyingSoftNumber: undefined,
            alreadyOneEnrollNumber: undefined,
            alreadyTwoEnrollNumber: undefined,
            alreadyThreeEnrollNumber: undefined,
            applyingOneEnrollNumber: undefined,
            applyingTwoEnrollNumber: undefined,
            applyingThreeEnrollNumber: undefined,
            inEnrollNumber: undefined,
            inClinicNumber: undefined,
            inReviewNumber: undefined,
            currentProjectProgress: undefined,
            nextPlan: undefined,
            certificationOne: undefined,
            certificationTwo: undefined,
            certificationThree: undefined,
            talentSituation: undefined,
            corporateHonors: undefined,
            employmentNeeds: undefined,
            landUseRequirements: undefined,
            isExportPlan: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.companyImplementationForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.companyImplementationForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delCompanyImplementation(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
            this.loading = false
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return exportCompanyImplementation(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(() => {
        })
    }
  }
}
</script>
